# 电信网关破解
import requests

headers = {
    "User-Agent":
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) \
    Chrome/54.0.2840.99 Safari/537.36",
    "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
    "Accept-Encoding": "gzip, deflate"
}

cookies = {
    'SESSIONID':'boasid44f1f8e5',
    'UID':'useradmin',
    'PSW':'tpaau'
}


def login(session):
    form_login = {"name": "userAdmin", "password": "tpaau"}
    url_login = "http://192.168.1.1/cgi-bin/cgic_get.cgi"
    session.post(url_login, data=form_login)


def set_net(session):
    form_net = {"name": "userAdmin", "password": "tpaau"}
    url_net = "http://192.168.1.1/cgi-bin/upgrade.asp"
    session.post(url_net, data=form_net)


def upgrade(session):
    form_upgrade = {"name": "userAdmin", "password": "tpaau"}
    url_upgrade = "http://192.168.1.1/cgi-bin/upgrade.asp"
    response = session.post(url_upgrade, data=form_upgrade,cookies=cookies)
    res_body = response.content.decode('gbk')
    print(res_body)


def config_file(session):
    url_cfg = "http://192.168.1.1/romfile.cfg"
    stream = session.get(url_cfg, cookies=cookies, stream=True)
    f = open("F:/config.bin", 'wb')
    for chunk in stream.iter_content(chunk_size=512):
        if chunk:
            f.write(chunk)


session = requests.session()
# login(session)
upgrade(session)
config_file(session)
